package common

import (
	"os"
	"syscall"
)

const (
	Log                   string = "/root/judge/log.txt"
	Network               string = "tcp"
	Port                  string = ":9999"
	TmpPath               string = "/root/judge/tmp"
	CgroupCpu             string = "/sys/fs/cgroup/cpu/judge_sandbox/"
	CgroupCpuPath         string = "/sys/fs/cgroup/cpu/judge_sandbox/%s"
	CgroupMemory          string = "/sys/fs/cgroup/memory/judge_sandbox"
	CgroupMemoryPath      string = "/sys/fs/cgroup/memory/judge_sandbox/%s"
	Tasks                 string = "tasks"
	MemoryLimitInBytes    string = "memory.limit_in_bytes"
	MemorySwapiness       string = "memory.swappiness"
	MemoryOOMControl      string = "memory.oom_control"
	MemoryMaxUsageInBytes string = "memory.max_usage_in_bytes"
	CpuCfsQuotaUs         string = "cpu.cfs_quota_us"
	CpuCfsPeriodUs        string = "cpu.cfs_period_us"
	CpuDefaultQuota       string = "10000"
	CpuDefaultPeriod      string = "100000"
)

var LogFile, _ = os.OpenFile(Log, syscall.O_WRONLY|syscall.O_APPEND|syscall.O_CREAT, 0666)

// overlay后的绝对路径
const (
	Javac      string = "/java/jdk-11/bin/javac"
	Java       string = "/java/jdk-11/bin/java"
	CCompile   string = "gcc"
	CppCompile string = "g++"
	GoCompile  string = "/go/go1.17.2/bin/go"
	Python     string = "/python/out-3.10.0/bin/python3"
)

// judge result type
const (
	Accepted            string = "Accepted"            //程序通过
	CompileError        string = "CompileError"        //编译错误
	RuntimeError        string = "RuntimeError"        //运行时错误
	MemoryLimitExceeded string = "MemoryLimitExceeded" //超出内存限制
	TimeLimitExceeded   string = "TimeLimitExceeded"   //运行超出时间限制
	WrongAnswer         string = "WrongAnswer"         //答案不完全正确
)

type JudgeRequest struct {
	Uuid                string   `json:"uuid"`
	Lang                string   `json:"lang"`       // java,golang,c,c++,python
	SourceCode          string   `json:"sourceCode"` // Main.java
	UseCases            []string `json:"useCases"`
	Answers             []string `json:"answers"`
	MaxMemoryLimit      string   `json:"maxMemoryLimit"`      // m 256m
	MaxRunningTimeLimit int      `json:"maxRunningTimeLimit"` // ms 3000
}

type JudgeResponse struct {
	Uuid             string   `json:"uuid"`
	Lang             string   `json:"lang"` // java,golang,c,c++,python
	UseCases         []string `json:"useCases"`
	Answers          []string `json:"answers"`
	Results          []string `json:"results"`
	UsedMaxMemory    int      `json:"usedMaxMemory"` //直接返回所用字节数
	RunningTime      int      `json:"runningTime"`
	ResultType       string   `json:"resultType"`
	AnswerErrorIndex int      `json:"answerErrorIndex"`
	ErrorMessage     string   `json:"errorMessage"`
}
